home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2008 February / PCWFEB08.iso / Software / Freeware / Miro 1.0 / Miro_Installer.exe / Miro_Downloader.exe / dl_daemon / command.pyc (.txt) < prev    next >
Encoding:
Python Compiled Bytecode  |  2007-11-12  |  10.0 KB  |  271 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 2.5)
  3.  
  4. import time
  5. import random
  6. import socket
  7. import eventloop
  8. import logging
  9. DAEMONIC_THREAD_TIMEOUT = 2
  10.  
  11. class Command:
  12.     
  13.     def __init__(self, daemon, *args, **kws):
  14.         self.id = 'cmd%08d' % random.randint(0, 99999999)
  15.         self.orig = True
  16.         self.args = args
  17.         self.kws = kws
  18.         self.daemon = daemon
  19.  
  20.     
  21.     def setDaemon(self, daemon):
  22.         self.daemon = daemon
  23.  
  24.     
  25.     def send(self, callback = None):
  26.         if self.daemon.shutdown:
  27.             return None
  28.         
  29.         (None, eventloop.addIdle)((lambda : self.daemon.send(self, callback)), 'sending command %s' % repr(self))
  30.  
  31.     
  32.     def setReturnValue(self, ret):
  33.         self.orig = False
  34.         self.ret = ret
  35.  
  36.     
  37.     def getReturnValue(self):
  38.         return self.ret
  39.  
  40.     
  41.     def action(self):
  42.         logging.warning('no action defined for command %s', self.id)
  43.  
  44.     
  45.     def __getstate__(self):
  46.         out = {
  47.             'id': self.id,
  48.             'args': self.args,
  49.             'kws': self.kws,
  50.             'orig': self.orig }
  51.         
  52.         try:
  53.             out['ret'] = self.ret
  54.         except AttributeError:
  55.             pass
  56.  
  57.         return out
  58.  
  59.     
  60.     def __setstate__(self, data):
  61.         self.id = data['id']
  62.         self.kws = data['kws']
  63.         self.args = data['args']
  64.         self.orig = data['orig']
  65.         
  66.         try:
  67.             self.ret = data['ret']
  68.         except KeyError:
  69.             pass
  70.  
  71.  
  72.  
  73.  
  74. class FindHTTPAuthCommand(Command):
  75.     
  76.     def action(self):
  77.         import httpauth
  78.         id = self.args[0]
  79.         args = self.args[1:]
  80.         
  81.         def callback(authHeader):
  82.             c = GotHTTPAuthCommand(self.daemon, id, authHeader)
  83.             c.send()
  84.  
  85.         httpauth.findHTTPAuth(callback, *args)
  86.  
  87.  
  88.  
  89. class AskForHTTPAuthCommand(Command):
  90.     
  91.     def action(self):
  92.         import httpauth
  93.         id = self.args[0]
  94.         args = self.args[1:]
  95.         
  96.         def callback(authHeader):
  97.             c = GotHTTPAuthCommand(self.daemon, id, authHeader)
  98.             c.send()
  99.  
  100.         httpauth.askForHTTPAuth(callback, *args)
  101.  
  102.  
  103.  
  104. class UpdateDownloadStatus(Command):
  105.     
  106.     def action(self):
  107.         RemoteDownloader = RemoteDownloader
  108.         import downloader
  109.         return RemoteDownloader.updateStatus(*self.args, **self.kws)
  110.  
  111.  
  112.  
  113. class BatchUpdateDownloadStatus(Command):
  114.     
  115.     def action(self):
  116.         RemoteDownloader = RemoteDownloader
  117.         import downloader
  118.         for status in self.args[0]:
  119.             RemoteDownloader.updateStatus(status)
  120.         
  121.  
  122.  
  123.  
  124. class DownloaderErrorCommand(Command):
  125.     
  126.     def action(self):
  127.         import util
  128.         util.failed('In Downloader process', details = self.args[0])
  129.  
  130.  
  131.  
  132. class ShutDownResponseCommand(Command):
  133.     
  134.     def action(self):
  135.         self.daemon.shutdownResponse()
  136.  
  137.  
  138.  
  139. class InitialConfigCommand(Command):
  140.     
  141.     def action(self):
  142.         import config
  143.         config.setDictionary(*self.args, **self.kws)
  144.  
  145.  
  146.  
  147. class UpdateConfigCommand(Command):
  148.     
  149.     def action(self):
  150.         import config
  151.         config.updateDictionary(*self.args, **self.kws)
  152.  
  153.  
  154.  
  155. class StartNewDownloadCommand(Command):
  156.     
  157.     def action(self):
  158.         download = download
  159.         import dl_daemon
  160.         return download.startNewDownload(*self.args, **self.kws)
  161.  
  162.  
  163.  
  164. class StartDownloadCommand(Command):
  165.     
  166.     def action(self):
  167.         download = download
  168.         import dl_daemon
  169.         return download.startDownload(*self.args, **self.kws)
  170.  
  171.  
  172.  
  173. class PauseDownloadCommand(Command):
  174.     
  175.     def action(self):
  176.         download = download
  177.         import dl_daemon
  178.         return download.pauseDownload(*self.args, **self.kws)
  179.  
  180.  
  181.  
  182. class StopDownloadCommand(Command):
  183.     
  184.     def action(self):
  185.         download = download
  186.         import dl_daemon
  187.         return download.stopDownload(*self.args, **self.kws)
  188.  
  189.  
  190.  
  191. class StopUploadCommand(Command):
  192.     
  193.     def action(self):
  194.         download = download
  195.         import dl_daemon
  196.         return download.stopUpload(*self.args, **self.kws)
  197.  
  198.  
  199.  
  200. class GetDownloadStatusCommand(Command):
  201.     
  202.     def action(self):
  203.         download = download
  204.         import dl_daemon
  205.         return download.getDownloadStatus(*self.args, **self.kws)
  206.  
  207.  
  208.  
  209. class RestoreDownloaderCommand(Command):
  210.     
  211.     def action(self):
  212.         download = download
  213.         import dl_daemon
  214.         return download.restoreDownloader(*self.args, **self.kws)
  215.  
  216.  
  217.  
  218. class MigrateDownloadCommand(Command):
  219.     
  220.     def action(self):
  221.         download = download
  222.         import dl_daemon
  223.         return download.migrateDownload(*self.args, **self.kws)
  224.  
  225.  
  226.  
  227. class GotHTTPAuthCommand(Command):
  228.     
  229.     def action(self):
  230.         (id, authHeader) = self.args
  231.         import httpauth
  232.         httpauth.handleHTTPAuthResponse(id, authHeader)
  233.  
  234.  
  235.  
  236. class ShutDownCommand(Command):
  237.     
  238.     def response_sent(self):
  239.         import eventloop
  240.         eventloop.quit()
  241.         logging.info('Shutdown complete')
  242.  
  243.     
  244.     def action(self):
  245.         starttime = time.time()
  246.         download = download
  247.         import dl_daemon
  248.         download.shutDown()
  249.         import threading
  250.         eventloop.threadPoolQuit()
  251.         for thread in threading.enumerate():
  252.             if thread != threading.currentThread() and not thread.isDaemon():
  253.                 thread.join()
  254.                 continue
  255.         
  256.         endtime = starttime + DAEMONIC_THREAD_TIMEOUT
  257.         for thread in threading.enumerate():
  258.             if thread != threading.currentThread():
  259.                 timeout = endtime - time.time()
  260.                 if timeout <= 0:
  261.                     break
  262.                 
  263.                 thread.join(timeout)
  264.                 continue
  265.         
  266.         c = ShutDownResponseCommand(self.daemon)
  267.         c.send(callback = self.response_sent)
  268.         self.daemon.shutdown = True
  269.  
  270.  
  271.